xenstored: Do not write to stderr if we are daemonised!
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 1 Aug 2007 11:55:10 +0000 (12:55 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 1 Aug 2007 11:55:10 +0000 (12:55 +0100)
This fixes client reader-thread deaths in which a 'garbage string' was
being read instead of a well-formed message header.
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/xenstore/utils.c
tools/xenstore/xenstored_core.c
tools/xenstore/xenstored_domain.c
tools/xenstore/xs_tdb_dump.c

index 45e71efd14c271ec090a0e18c2ad3195da9e6099..d7f5219a871a0e0684ca2933a2f87d78d86039e2 100644 (file)
@@ -8,20 +8,19 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <signal.h>
-
 #include "utils.h"
 
 void xprintf(const char *fmt, ...)
 {
-       static FILE *out = NULL;
        va_list args;
-       if (!out)
-               out = stderr;
+
+       if (!stderr)
+               return; /* could trace()? */
 
        va_start(args, fmt);
-       vfprintf(out, fmt, args);
+       vfprintf(stderr, fmt, args);
        va_end(args);
-       fflush(out);
+       fflush(stderr);
 }
 
 void barf(const char *fmt, ...)
index f34a698cb4ac8668e5c4c6f2f2ab292733cc4166..fc3171f14b6d87c7cdbfe362ebed475f69d5950c 100644 (file)
@@ -1820,7 +1820,9 @@ int main(int argc, char *argv[])
        if (pidfile)
                write_pidfile(pidfile);
 
-       talloc_enable_leak_report_full();
+       /* Talloc leak reports go to stderr, which is closed if we fork. */
+       if (!dofork)
+               talloc_enable_leak_report_full();
 
        /* Create sockets for them to listen to. */
        sock = talloc(talloc_autofree_context(), int);
@@ -1881,6 +1883,11 @@ int main(int argc, char *argv[])
                close(STDIN_FILENO);
                close(STDOUT_FILENO);
                close(STDERR_FILENO);
+
+               /* Get ourselves a nice xenstored crash if these are used. */
+               stdin = NULL;
+               stdout = NULL;
+               stderr = NULL;
        }
 
        signal(SIGHUP, trigger_reopen_log);
index d166c0556e1014dbd2379b23fbce728c17f2501a..ed422a52aa0db6a68c3e5f0309109b937df12330 100644 (file)
@@ -621,13 +621,8 @@ void domain_entry_fix(unsigned int domid, int num)
        struct domain *d;
 
        d = find_domain_by_domid(domid);
-       if (d) {
-               if ((d->nbentry += num) < 0) {
-                       eprintf("invalid domain entry number %d",
-                               d->nbentry);
-                       d->nbentry = 0;
-               }
-       }
+       if (d && ((d->nbentry += num) < 0))
+               d->nbentry = 0;
 }
 
 int domain_entry(struct connection *conn)
index 5f1382f41bf36e8c7fbe2f2f8b1fbe11cb5f1fe8..d3c515418ca5c068ee713a2ba0b6b022de8e6500 100644 (file)
@@ -4,7 +4,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdarg.h>
-
+#include <string.h>
 #include "xs_lib.h"
 #include "tdb.h"
 #include "talloc.h"